/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is Forte for Java, Community Edition. The Initial * Developer of the Original Code is Sun Microsystems, Inc. Portions * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.autoupdate; import java.awt.Dialog; import javax.swing.JButton; import java.util.ResourceBundle; import org.openide.DialogDescriptor; import org.openide.NotifyDescriptor; import org.openide.TopManager; import org.openide.util.NbBundle; import org.openide.util.HelpCtx; /** Used to let user now the web will be checked for new updates. And * optionally config the process * @author Petr Hrebejk */ public class AutoCheckInfo extends javax.swing.JPanel { /** The resource bundle */ private static final ResourceBundle bundle = NbBundle.getBundle( LicenceDialog.class ); /** Preferred size of this dialog */ private static final java.awt.Dimension preferredSize = new java.awt.Dimension( 620, 475 ); /** The only Licence panel instance in system */ private static AutoCheckInfo dialogPanel; /** The dialog descriptor of licence dialog */ private static DialogDescriptor dialogDescriptor = null; /** The Licence dialog */ private static java.awt.Dialog dialog = null; /** Licence dialog Accept button */ private Settings settings; /** Result of the action */ private boolean result; /** prefferd width of dialog */ private int prefX = 0; private java.awt.Dimension prefSize = null; /** Creates new form LicencePanel */ public AutoCheckInfo( String message, int messageType ) { settings = Settings.getShared(); int period = settings.getPeriod(); initComponents (); Settings.PeriodPropertyEditor ppe = new Settings.PeriodPropertyEditor(); String[] tags = ppe.getTags(); for ( int i = 0; i < tags.length; i++ ) periodComboBox.addItem( tags[i] ); messageText.setText( message ); iconLabel.setIcon( getIconForType( messageType ) ); beforeCheckBox.setSelected( settings.isAskBefore() ); negativCheckBox.setSelected( settings.isNegativeResults() ); periodComboBox.setSelectedIndex( period ); prefX = getPreferredSize().width; regnumTextField.setText( settings.getRegistrationNumber() ); configPanel.setBorder (new javax.swing.border.TitledBorder(bundle.getString("AutoCheckInfo.configBorder"))); extSettingsPanel.setBorder (new javax.swing.border.TitledBorder(bundle.getString("AutoCheckInfo.additionalBorder"))); configPanel.setVisible( false ); extSettingsPanel.setVisible( false ); } /** Overload getPreffered size to get a bit bigger dialog */ public java.awt.Dimension getPreferredSize() { if ( prefX == 0 ) { return super.getPreferredSize(); } //if ( prefSize == null ) prefSize = super.getPreferredSize(); prefSize.width = java.lang.Math.max( prefSize.width, prefX ); return prefSize; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () {//GEN-BEGIN:initComponents messagePanel = new javax.swing.JPanel (); iconLabel = new javax.swing.JLabel (); messageText = new javax.swing.JTextArea (); configCheckBox = new javax.swing.JCheckBox (); configPanel = new javax.swing.JPanel (); jLabel2 = new javax.swing.JLabel (); periodComboBox = new javax.swing.JComboBox (); beforeCheckBox = new javax.swing.JCheckBox (); negativCheckBox = new javax.swing.JCheckBox (); extSettingsPanel = new javax.swing.JPanel (); jLabel1 = new javax.swing.JLabel (); regnumTextField = new javax.swing.JTextField (); proxyButton = new javax.swing.JButton (); setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints1; setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(8, 8, 8, 8))); messagePanel.setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints2; gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints2.weighty = 1.0; messagePanel.add (iconLabel, gridBagConstraints2); messageText.setOpaque (false); messageText.setEditable (false); messageText.setFont (new java.awt.Font ("Dialog", 0, 12)); // NOI18N gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridwidth = 0; gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints2.insets = new java.awt.Insets (0, 18, 0, 0); gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints2.weightx = 1.0; gridBagConstraints2.weighty = 1.0; messagePanel.add (messageText, gridBagConstraints2); configCheckBox.setText (org.openide.util.NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.configCheckBox.text")); configCheckBox.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { configButtonActionPerformed (evt); } } ); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridx = 1; gridBagConstraints2.gridy = 1; gridBagConstraints2.gridwidth = 0; gridBagConstraints2.insets = new java.awt.Insets (8, 18, 0, 0); gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST; messagePanel.add (configCheckBox, gridBagConstraints2); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.weighty = 1.0; add (messagePanel, gridBagConstraints1); configPanel.setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints3; jLabel2.setText (org.openide.util.NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.jLabel2.text")); gridBagConstraints3 = new java.awt.GridBagConstraints (); gridBagConstraints3.gridwidth = -1; gridBagConstraints3.insets = new java.awt.Insets (4, 8, 0, 5); gridBagConstraints3.anchor = java.awt.GridBagConstraints.WEST; configPanel.add (jLabel2, gridBagConstraints3); periodComboBox.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { periodComboBoxActionPerformed (evt); } } ); gridBagConstraints3 = new java.awt.GridBagConstraints (); gridBagConstraints3.gridwidth = 0; gridBagConstraints3.insets = new java.awt.Insets (4, 0, 0, 0); gridBagConstraints3.anchor = java.awt.GridBagConstraints.WEST; configPanel.add (periodComboBox, gridBagConstraints3); beforeCheckBox.setText (org.openide.util.NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.jCheckBox1.text")); beforeCheckBox.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { beforeCheckBoxActionPerformed (evt); } } ); gridBagConstraints3 = new java.awt.GridBagConstraints (); gridBagConstraints3.gridwidth = 0; gridBagConstraints3.insets = new java.awt.Insets (0, 8, 0, 0); gridBagConstraints3.anchor = java.awt.GridBagConstraints.WEST; configPanel.add (beforeCheckBox, gridBagConstraints3); negativCheckBox.setText (org.openide.util.NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.jCheckBox2.text")); negativCheckBox.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { negativCheckBoxActionPerformed (evt); } } ); gridBagConstraints3 = new java.awt.GridBagConstraints (); gridBagConstraints3.gridx = 0; gridBagConstraints3.gridy = 2; gridBagConstraints3.gridwidth = 0; gridBagConstraints3.insets = new java.awt.Insets (0, 8, 8, 0); gridBagConstraints3.anchor = java.awt.GridBagConstraints.WEST; configPanel.add (negativCheckBox, gridBagConstraints3); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (12, 0, 0, 0); gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.weighty = 1.0; add (configPanel, gridBagConstraints1); extSettingsPanel.setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints4; jLabel1.setText (org.openide.util.NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.jLabel1.text")); gridBagConstraints4 = new java.awt.GridBagConstraints (); gridBagConstraints4.insets = new java.awt.Insets (4, 8, 0, 0); gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST; extSettingsPanel.add (jLabel1, gridBagConstraints4); regnumTextField.setColumns (15); regnumTextField.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { regnumTextFieldActionPerformed (evt); } } ); regnumTextField.addFocusListener (new java.awt.event.FocusAdapter () { public void focusLost (java.awt.event.FocusEvent evt) { regnumTextFieldFocusLost (evt); } } ); gridBagConstraints4 = new java.awt.GridBagConstraints (); gridBagConstraints4.gridwidth = 0; gridBagConstraints4.insets = new java.awt.Insets (4, 8, 0, 0); gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST; extSettingsPanel.add (regnumTextField, gridBagConstraints4); proxyButton.setText (org.openide.util.NbBundle.getBundle(AutoCheckInfo.class).getString("AutoCheckInfo.proxyButton.text")); proxyButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { proxyButtonActionPerformed (evt); } } ); gridBagConstraints4 = new java.awt.GridBagConstraints (); gridBagConstraints4.gridwidth = 0; gridBagConstraints4.insets = new java.awt.Insets (7, 8, 8, 0); gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST; extSettingsPanel.add (proxyButton, gridBagConstraints4); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.gridheight = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints1.insets = new java.awt.Insets (12, 0, 0, 0); gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.weighty = 1.0; add (extSettingsPanel, gridBagConstraints1); }//GEN-END:initComponents private void proxyButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_proxyButtonActionPerformed ProxyDialog.showDialog(); }//GEN-LAST:event_proxyButtonActionPerformed private void regnumTextFieldFocusLost (java.awt.event.FocusEvent evt) {//GEN-FIRST:event_regnumTextFieldFocusLost setRegNum(); }//GEN-LAST:event_regnumTextFieldFocusLost private void regnumTextFieldActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_regnumTextFieldActionPerformed setRegNum(); }//GEN-LAST:event_regnumTextFieldActionPerformed private void periodComboBoxActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_periodComboBoxActionPerformed settings.setPeriod( periodComboBox.getSelectedIndex() ); }//GEN-LAST:event_periodComboBoxActionPerformed private void negativCheckBoxActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_negativCheckBoxActionPerformed settings.setNegativeResults( negativCheckBox.isSelected() ); }//GEN-LAST:event_negativCheckBoxActionPerformed private void beforeCheckBoxActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_beforeCheckBoxActionPerformed settings.setAskBefore( beforeCheckBox.isSelected() ); }//GEN-LAST:event_beforeCheckBoxActionPerformed private void configButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configButtonActionPerformed configPanel.setVisible( configCheckBox.isSelected() ); extSettingsPanel.setVisible( configCheckBox.isSelected() ); if ( getTopLevelAncestor() instanceof java.awt.Window ) { ((java.awt.Window)getTopLevelAncestor()).pack(); } }//GEN-LAST:event_configButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel messagePanel; private javax.swing.JLabel iconLabel; private javax.swing.JTextArea messageText; private javax.swing.JCheckBox configCheckBox; private javax.swing.JPanel configPanel; private javax.swing.JLabel jLabel2; private javax.swing.JComboBox periodComboBox; private javax.swing.JCheckBox beforeCheckBox; private javax.swing.JCheckBox negativCheckBox; private javax.swing.JPanel extSettingsPanel; private javax.swing.JLabel jLabel1; private javax.swing.JTextField regnumTextField; private javax.swing.JButton proxyButton; // End of variables declaration//GEN-END:variables static boolean showDialog( String message, int messageType, boolean yesNo ) { //if ( dialog == null ) { DialogDescriptor dd = createDialog( message, messageType, yesNo ); //} //dialog.invalidate(); //dialog.pack(); Dialog dialog = TopManager.getDefault().createDialog( dd ); dialog.show(); dialogPanel.setRegNum(); return yesNo ? dd.getValue() == DialogDescriptor.YES_OPTION : true ; } private static DialogDescriptor createDialog( String message, int messageType, boolean yesNo ) { DialogDescriptor dd; if ( yesNo ) { dd = new DialogDescriptor( dialogPanel = new AutoCheckInfo( message, messageType), bundle.getString( "CTL_AutoCheck_Title" ), true, // Modal DialogDescriptor.YES_NO_OPTION, // Option list DialogDescriptor.YES_OPTION, // Default DialogDescriptor.BOTTOM_ALIGN, // Align new HelpCtx ( AutoCheckInfo.class ), // Help null ); } else { dd = new DialogDescriptor( dialogPanel = new AutoCheckInfo( message, messageType), bundle.getString( "CTL_AutoCheck_Title" ), true, // Modal new Object [] { DialogDescriptor.OK_OPTION }, // Option list DialogDescriptor.OK_OPTION, // Default DialogDescriptor.BOTTOM_ALIGN, // Align new HelpCtx ( AutoCheckInfo.class ), // Help null ); dd.setClosingOptions( null ); } return dd; } /** Gets the right icon */ private static javax.swing.Icon getIconForType(int messageType) { if(messageType < 0 || messageType > 3) return null; switch(messageType) { case 0: return javax.swing.UIManager.getIcon("OptionPane.errorIcon"); // NOI18N case 1: return javax.swing.UIManager.getIcon("OptionPane.informationIcon"); // NOI18N case 2: return javax.swing.UIManager.getIcon("OptionPane.warningIcon"); // NOI18N case 3: return javax.swing.UIManager.getIcon("OptionPane.questionIcon"); // NOI18N } return null; } /** Sets the registratiopn number */ void setRegNum() { settings.setRegistrationNumber( regnumTextField.getText() ); } /** Moves specified window to the center of the screen */ /* public static void centerWindow (Window w) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension dialogSize = w.getSize(); w.setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2); } */ } /* * Log * 6 Gandalf 1.5 2/7/00 Petr Hrebejk Status line text added * while autochecking * 5 Gandalf 1.4 1/12/00 Petr Hrebejk i18n mk2 * 4 Gandalf 1.3 1/12/00 Petr Hrebejk i18n * 3 Gandalf 1.2 1/9/00 Petr Hrebejk Proxy Config and * Registration number added * 2 Gandalf 1.1 12/22/99 Petr Hrebejk Various bugfixes * 1 Gandalf 1.0 12/1/99 Petr Hrebejk * $ */